﻿/**************************************************************
*作者：Leon
*创建时间：2022/5/2 18:12:18
**************************************************************/
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace StudentManagerDemo.Repository;
public class User : IdentityUser
{
    public User()
    {
    }
}

public class HomePageViewModel
{
    public IEnumerable<Employee> Employees { get; set; }
}

public class EmployeeEditViewModel
{
    [Required, MaxLength(80)]
    public string Name { get; set; }
}


public class SQLEmployeeData
{
    private HelloWorldDBContext _context { get; set; }

    public SQLEmployeeData(HelloWorldDBContext context)
    {
        _context = context;
    }

    public void Add(Employee emp)
    {
        _context.Add(emp);
        _context.SaveChanges();
    }

    public Employee Get(int ID)
    {
        return _context.Employees.FirstOrDefault(e => e.ID == ID);
    }

    public IEnumerable<Employee> GetAll()
    {
        return _context.Employees.ToList<Employee>();
    }
}

public class HelloWorldDBContext : IdentityDbContext<User>
{
    public HelloWorldDBContext() { }

    public HelloWorldDBContext(DbContextOptions<HelloWorldDBContext> options)
        : base(options)
    {

    }
    public DbSet<Employee> Employees { get; set; }
}
public class Employee
{
    public int ID { get; set; }
    [MaxLength(50)]
    public string Name { get; set; }
}
